package org.example.elm_xiangmu.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.elm_xiangmu.po.Business;
import org.example.elm_xiangmu.po.FoodType;
import org.example.elm_xiangmu.result.Result;
import org.example.elm_xiangmu.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/Business")
@Tag(name="商家")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @Operation(summary = "根据点餐分类编号查询商家信息")
    @GetMapping("/listBusinessByOrderTypeId/{orderTypeId}")
    public Result listBusinessByOrderTypeId(@Parameter(description = "点餐分类编号") @PathVariable Integer orderTypeId) {

        List<Business> businessList = businessService.list(orderTypeId);
        if (businessList == null || businessList.size() == 0) {
            return  Result.error("查询分类不存在或没有该商家");
        }
        return Result.success(businessList,"查找商家成功");
    }

    @Operation(summary = "根据商家编号查询商家信息")
    @GetMapping("/getBusinessById/{businessId}")
    public Result getBusinessById(@Parameter(description = "商家编号") @PathVariable Integer businessId){

        return businessService.getById(businessId);
    }

    @Operation(summary = "查询全部商家信息")
    @GetMapping("/getAllBusiness")
    public Result getAllBusiness(){
        List<Business> businessList =businessService.getAllBusiness();
        return Result.success(businessList,"查询商家成功");
    }

}
